<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 优先级队列深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-shadow {
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .card-shadow:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .code-dots {
            display: flex;
            gap: 8px;
        }
        
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
            color: #e6e6e6;
            font-family: 'Consolas', 'Monaco', monospace;
            line-height: 1.6;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 16px;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .icon-purple { background: rgba(102, 126, 234, 0.1); color: #667eea; }
        .icon-pink { background: rgba(236, 72, 153, 0.1); color: #ec4899; }
        .icon-green { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
        .icon-orange { background: rgba(251, 146, 60, 0.1); color: #fb923c; }
        
        .section-title {
            position: relative;
            padding-left: 20px;
            margin-bottom: 30px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .complexity-card {
            background: white;
            border-radius: 16px;
            padding: 20px;
            display: flex;
            align-items: center;
            gap: 20px;
            transition: all 0.3s ease;
        }
        
        .complexity-card:hover {
            transform: translateX(10px);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0 8px 0 0;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <i class="fas fa-layer-group mr-4"></i>
                    Java 优先级队列
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">深入理解 PriorityQueue 的原理与应用</p>
                <div class="flex justify-center gap-4 text-sm">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-clock mr-2"></i>阅读时间：8分钟
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-code mr-2"></i>代码示例
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-chart-line mr-2"></i>性能分析
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-6xl mx-auto">
            
            <!-- Introduction Card -->
            <div class="bg-white rounded-2xl card-shadow p-8 mb-12">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">J</span>ava 中的优先级队列（<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">PriorityQueue</code>）是一个基于优先级的队列数据结构，它是 <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">java.util</code> 包中的一个类。<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">PriorityQueue</code> 实现了 <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">Queue</code> 接口，并提供了基于元素优先级的排序。
                </p>
            </div>

            <!-- Basic Concept -->
            <div class="mb-12">
                <h2 class="section-title text-3xl font-bold text-gray-800">基本概念</h2>
                <div class="bg-white rounded-2xl card-shadow p-8">
                    <p class="text-lg leading-relaxed text-gray-700 mb-6">
                        优先级队列是一种特殊的队列，其中每个元素都有一个优先级。队列中的元素是按照优先级顺序进行处理的，优先级高的元素会先被取出。与普通队列不同，优先级队列不会按照元素的插入顺序进行处理。
                    </p>
                    
                    <!-- Visual Representation -->
                    <div class="bg-gray-50 rounded-xl p-6">
                        <div class="mermaid">
                            graph LR
                                A[插入元素] --> B{优先级队列}
                                B --> C[自动排序]
                                C --> D[最高优先级元素在队首]
                                D --> E[取出元素]
                                style B fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                                style C fill:#ec4899,stroke:#fff,stroke-width:2px,color:#fff
                                style D fill:#22c55e,stroke:#fff,stroke-width:2px,color:#fff
                        </div>
                    </div>
                </div>
            </div>

            <!-- Features Grid -->
            <div class="mb-12">
                <h2 class="section-title text-3xl font-bold text-gray-800">核心特性</h2>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-2xl card-shadow p-8">
                        <div class="feature-icon icon-purple">
                            <i class="fas fa-sort-amount-up"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">自动排序</h3>
                        <p class="text-gray-600">PriorityQueue 内部会自动根据元素的自然顺序或者自定义的比较器进行排序。最小值（或最大值）会在队列的前面。</p>
                    </div>
                    
                    <div class="bg-white rounded-2xl card-shadow p-8">
                        <div class="feature-icon icon-pink">
                            <i class="fas fa-infinity"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">无容量限制</h3>
                        <p class="text-gray-600">PriorityQueue 默认不限制容量，但受限于系统内存。队列会根据需要自动扩容。</p>
                    </div>
                    
                    <div class="bg-white rounded-2xl card-shadow p-8">
                        <div class="feature-icon icon-green">
                            <i class="fas fa-ban"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">不支持 null 元素</h3>
                        <p class="text-gray-600">队列中不能包含 null 元素，这是为了避免在比较时出现空指针异常。</p>
                    </div>
                    
                    <div class="bg-white rounded-2xl card-shadow p-8">
                        <div class="feature-icon icon-orange">
                            <i class="fas fa-exclamation-triangle"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">非线程安全</h3>
                        <p class="text-gray-600">PriorityQueue 不是线程安全的。如果需要在多线程环境中使用，需要外部同步。</p>
                    </div>
                </div>
            </div>

            <!-- Internal Implementation -->
            <div class="mb-12">
                <h2 class="section-title text-3xl font-bold text-gray-800">内部实现原理</h2>
                <div class="bg-white rounded-2xl card-shadow p-8">
                    <p class="text-lg leading-relaxed text-gray-700 mb-6">
                        <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">PriorityQueue</code> 是基于<strong>二叉堆（Binary Heap）</strong>实现的。具体来说，它通常使用<strong>小顶堆（Min-Heap）</strong>作为内部数据结构，保证了堆顶元素是队列中最小的元素（可以通过比较器实现最大堆）。
                    </p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-6">
                            <h4 class="text-xl font-bold mb-4 text-purple-700">
                                <i class="fas fa-tree mr-2"></i>完全二叉树
                            </h4>
                            <p class="text-gray-700">堆是一种完全二叉树，因此所有层都是完全填满的，除了最后一层可能不满。</p>
                        </div>
                        
                        <div class="bg-gradient-to-br from-blue-50 to-green-50 rounded-xl p-6">
                            <h4 class="text-xl font-bold mb-4 text-blue-700">
                                <i class="fas fa-layer-group mr-2"></i>堆的性质
                            </h4>
                            <p class="text-gray-700">对于小顶堆，父节点的值总是不大于其子节点的值。这样，最小值总是位于堆顶。</p>
                        </div>
                    </div>

                    <!-- Heap Visualization -->
                    <div class="bg-gray-50 rounded-xl p-6">
                        <h4 class="text-lg font-bold mb-4 text-center">二叉堆结构示意图</h4>
                        <div class="mermaid">
                            graph TD
                                A[1<br/>堆顶最小值] --> B[3]
                                A --> C[2]
                                B --> D[7]
                                B --> E[4]
                                C --> F[5]
                                C --> G[6]
                                style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                                style B fill:#ec4899,stroke:#fff,stroke-width:2px,color:#fff
                                style C fill:#ec4899,stroke:#fff,stroke-width:2px,color:#fff
                                style D fill:#22c55e,stroke:#fff,stroke-width:2px,color:#fff
                                style E fill:#22c55e,stroke:#fff,stroke-width:2px,color:#fff
                                style F fill